package logic

import (
	"context"
	"fmt"
	"work_srv/models"

	"work_srv/internal/svc"
	"work_srv/work"

	"github.com/zeromicro/go-zero/core/logx"
)

type JobCreateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewJobCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *JobCreateLogic {
	return &JobCreateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 招聘发布
func (l *JobCreateLogic) JobCreate(in *work.JobCreateRequest) (*work.JobCreateResponse, error) {
	// todo: add your logic here and delete this line
	var err error
	jobs := models.Job{
		Name:        in.Name,
		Type:        in.Type,
		WorkAddress: in.WorkAddress,
		Info:        in.Info,
		Price:       float64(in.Price),
		Desc:        in.Desc,
	}
	if err = jobs.JobCreate(); err != nil {
		logx.Error("失败")
		return nil, fmt.Errorf("失败")
	}
	return &work.JobCreateResponse{
		Id: int64(jobs.ID),
	}, nil
}
